Skip to content

Optional struct

Attributes: [DebuggerDisplay("HasValue = {HasValue}, Value = {_value}")]

Defined in

Namespace: ReactiveUI.Primitives Assembly: ReactiveUI.Primitives.Core.dll Full name: ReactiveUI.Primitives.Optional<T> Modifiers: public sealed

Summary

View source

Represents an optional value that may or may not be present.

Applies to

net10.0, net10.0-browserwasm1.0, net10.0-desktop1.0, net9.0, net9.0-browserwasm1.0, net9.0-desktop1.0, net8.0, net8.0-ios17.5, net8.0-maccatalyst17.5, net8.0-macos14.2, net8.0-macos14.5, net8.0-tvos17.2, netstandard2.1, net462, net481, net471

Class hierarchy
classDiagram
class Optional~T~
class IEquatable~Optional~T~~ {
    <>
}
IEquatable~Optional~T~~ <|.. Optional~T~

Implements: IEquatable>

Remarks

Use this struct to indicate the presence or absence of a value without resorting to null references. When an instance has a value, the HasValue property is true and the Value property returns the contained value. If no value is present, HasValue is false and accessing Value throws an exception. This pattern is useful for APIs that need to distinguish between an explicit 'no value' state and a default value.

Constructors

NameSummary
.ctorInitializes a new instance of the [Optional](# struct.

Properties

NameSummary
static EmptyGets an empty instance of the [Optional](# type that contains no value.
static NoneGets an empty optional value.
HasValueGets a value indicating whether the current instance has a valid value assigned.
ValueGets the value contained in the optional object.

Methods

NameSummary
static SomeCreates an optional value containing a value.
static CreateCreates the specified value.
static FromOptionalGets the value from the optional value.
static ToOptionalGets the optional from a value.
ToString
GetHashCode
Equals

Operators

NameSummary
static op_ImplicitImplicit cast from the value to the optional.
static op_ExplicitExplicit cast from option to value.
static op_Inequality
static op_Equality